package com.example.fengyungo_user.service;

import android.app.IntentService;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;

import androidx.annotation.Nullable;

import com.example.fengyungo_user.constant.UserConstant;
import com.example.fengyungo_user.domain.User;
import com.example.fengyungo_user.utils.BitmapUtils;
import com.example.fengyungo_user.utils.OssUtils;
import com.example.fengyungo_user.utils.UserUtils;


public class CommonIntentService extends IntentService {

    private static final String TAG = "CommonIntentService";

    public CommonIntentService() {
        super("CommonIntentService");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        Log.d(TAG, "onHandleIntent: ");
        User user = UserUtils.getUserInfoInService(this);
        String avatarUrl = user.getUserAvatar();
        Bitmap avatar = OssUtils.getBitmapFromOss(this,avatarUrl);
        Log.d(TAG, "onHandleIntent: avatar="+avatar);
        // 将图片存入SharedPreferences
        BitmapUtils.saveBitmapToSharedPreferences(avatar, this, UserConstant.AVATAR);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy");
    }
}